<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8" />
<meta name="generator" content="pandoc" />
<meta http-equiv="X-UA-Compatible" content="IE=EDGE" />

<meta name="viewport" content="width=device-width, initial-scale=1" />

<meta name="author" content="Edith Ross, Kerstin Haase" />

<meta name="date" content="2024-05-22" />

<title>Multi-sample analysis with ASCAT</title>

<script>// Pandoc 2.9 adds attributes on both header and div. We remove the former (to
// be compatible with the behavior of Pandoc < 2.8).
document.addEventListener('DOMContentLoaded', function(e) {
  var hs = document.querySelectorAll("div.section[class*='level'] > :first-child");
  var i, h, a;
  for (i = 0; i < hs.length; i++) {
    h = hs[i];
    if (!/^h[1-6]$/i.test(h.tagName)) continue;  // it should be a header h1-h6
    a = h.attributes;
    while (a.length > 0) h.removeAttribute(a[0].name);
  }
});
</script>

<style type="text/css">
  code{white-space: pre-wrap;}
  span.smallcaps{font-variant: small-caps;}
  span.underline{text-decoration: underline;}
  div.column{display: inline-block; vertical-align: top; width: 50%;}
  div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
  ul.task-list{list-style: none;}
    </style>



<style type="text/css">
  code {
    white-space: pre;
  }
  .sourceCode {
    overflow: visible;
  }
</style>
<style type="text/css" data-origin="pandoc">
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
div.sourceCode { margin: 1em 0; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
pre > code.sourceCode { white-space: pre-wrap; }
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
  { counter-reset: source-line 0; }
pre.numberSource code > span
  { position: relative; left: -4em; counter-increment: source-line; }
pre.numberSource code > span > a:first-child::before
  { content: counter(source-line);
    position: relative; left: -1em; text-align: right; vertical-align: baseline;
    border: none; display: inline-block;
    -webkit-touch-callout: none; -webkit-user-select: none;
    -khtml-user-select: none; -moz-user-select: none;
    -ms-user-select: none; user-select: none;
    padding: 0 4px; width: 4em;
    color: #aaaaaa;
  }
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa;  padding-left: 4px; }
div.sourceCode
  {   }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
code span.al { color: #ff0000; font-weight: bold; } /* Alert */
code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code span.at { color: #7d9029; } /* Attribute */
code span.bn { color: #40a070; } /* BaseN */
code span.bu { color: #008000; } /* BuiltIn */
code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code span.ch { color: #4070a0; } /* Char */
code span.cn { color: #880000; } /* Constant */
code span.co { color: #60a0b0; font-style: italic; } /* Comment */
code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code span.do { color: #ba2121; font-style: italic; } /* Documentation */
code span.dt { color: #902000; } /* DataType */
code span.dv { color: #40a070; } /* DecVal */
code span.er { color: #ff0000; font-weight: bold; } /* Error */
code span.ex { } /* Extension */
code span.fl { color: #40a070; } /* Float */
code span.fu { color: #06287e; } /* Function */
code span.im { color: #008000; font-weight: bold; } /* Import */
code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
code span.kw { color: #007020; font-weight: bold; } /* Keyword */
code span.op { color: #666666; } /* Operator */
code span.ot { color: #007020; } /* Other */
code span.pp { color: #bc7a00; } /* Preprocessor */
code span.sc { color: #4070a0; } /* SpecialChar */
code span.ss { color: #bb6688; } /* SpecialString */
code span.st { color: #4070a0; } /* String */
code span.va { color: #19177c; } /* Variable */
code span.vs { color: #4070a0; } /* VerbatimString */
code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */

</style>
<script>
// apply pandoc div.sourceCode style to pre.sourceCode instead
(function() {
  var sheets = document.styleSheets;
  for (var i = 0; i < sheets.length; i++) {
    if (sheets[i].ownerNode.dataset["origin"] !== "pandoc") continue;
    try { var rules = sheets[i].cssRules; } catch (e) { continue; }
    var j = 0;
    while (j < rules.length) {
      var rule = rules[j];
      // check if there is a div.sourceCode rule
      if (rule.type !== rule.STYLE_RULE || rule.selectorText !== "div.sourceCode") {
        j++;
        continue;
      }
      var style = rule.style.cssText;
      // check if color or background-color is set
      if (rule.style.color === '' && rule.style.backgroundColor === '') {
        j++;
        continue;
      }
      // replace div.sourceCode by a pre.sourceCode rule
      sheets[i].deleteRule(j);
      sheets[i].insertRule('pre.sourceCode{' + style + '}', j);
    }
  }
})();
</script>




<style type="text/css">body {
background-color: #fff;
margin: 1em auto;
max-width: 700px;
overflow: visible;
padding-left: 2em;
padding-right: 2em;
font-family: "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 14px;
line-height: 1.35;
}
#TOC {
clear: both;
margin: 0 0 10px 10px;
padding: 4px;
width: 400px;
border: 1px solid #CCCCCC;
border-radius: 5px;
background-color: #f6f6f6;
font-size: 13px;
line-height: 1.3;
}
#TOC .toctitle {
font-weight: bold;
font-size: 15px;
margin-left: 5px;
}
#TOC ul {
padding-left: 40px;
margin-left: -1.5em;
margin-top: 5px;
margin-bottom: 5px;
}
#TOC ul ul {
margin-left: -2em;
}
#TOC li {
line-height: 16px;
}
table {
margin: 1em auto;
border-width: 1px;
border-color: #DDDDDD;
border-style: outset;
border-collapse: collapse;
}
table th {
border-width: 2px;
padding: 5px;
border-style: inset;
}
table td {
border-width: 1px;
border-style: inset;
line-height: 18px;
padding: 5px 5px;
}
table, table th, table td {
border-left-style: none;
border-right-style: none;
}
table thead, table tr.even {
background-color: #f7f7f7;
}
p {
margin: 0.5em 0;
}
blockquote {
background-color: #f6f6f6;
padding: 0.25em 0.75em;
}
hr {
border-style: solid;
border: none;
border-top: 1px solid #777;
margin: 28px 0;
}
dl {
margin-left: 0;
}
dl dd {
margin-bottom: 13px;
margin-left: 13px;
}
dl dt {
font-weight: bold;
}
ul {
margin-top: 0;
}
ul li {
list-style: circle outside;
}
ul ul {
margin-bottom: 0;
}
pre, code {
background-color: #f7f7f7;
border-radius: 3px;
color: #333;
white-space: pre-wrap; 
}
pre {
border-radius: 3px;
margin: 5px 0px 10px 0px;
padding: 10px;
}
pre:not([class]) {
background-color: #f7f7f7;
}
code {
font-family: Consolas, Monaco, 'Courier New', monospace;
font-size: 85%;
}
p > code, li > code {
padding: 2px 0px;
}
div.figure {
text-align: center;
}
img {
background-color: #FFFFFF;
padding: 2px;
border: 1px solid #DDDDDD;
border-radius: 3px;
border: 1px solid #CCCCCC;
margin: 0 5px;
}
h1 {
margin-top: 0;
font-size: 35px;
line-height: 40px;
}
h2 {
border-bottom: 4px solid #f7f7f7;
padding-top: 10px;
padding-bottom: 2px;
font-size: 145%;
}
h3 {
border-bottom: 2px solid #f7f7f7;
padding-top: 10px;
font-size: 120%;
}
h4 {
border-bottom: 1px solid #f7f7f7;
margin-left: 8px;
font-size: 105%;
}
h5, h6 {
border-bottom: 1px solid #ccc;
font-size: 105%;
}
a {
color: #0033dd;
text-decoration: none;
}
a:hover {
color: #6666ff; }
a:visited {
color: #800080; }
a:visited:hover {
color: #BB00BB; }
a[href^="http:"] {
text-decoration: underline; }
a[href^="https:"] {
text-decoration: underline; }

code > span.kw { color: #555; font-weight: bold; } 
code > span.dt { color: #902000; } 
code > span.dv { color: #40a070; } 
code > span.bn { color: #d14; } 
code > span.fl { color: #d14; } 
code > span.ch { color: #d14; } 
code > span.st { color: #d14; } 
code > span.co { color: #888888; font-style: italic; } 
code > span.ot { color: #007020; } 
code > span.al { color: #ff0000; font-weight: bold; } 
code > span.fu { color: #900; font-weight: bold; } 
code > span.er { color: #a61717; background-color: #e3d2d2; } 
</style>




</head>

<body>




<h1 class="title toc-ignore">Multi-sample analysis with ASCAT</h1>
<h4 class="author">Edith Ross, Kerstin Haase</h4>
<h4 class="date">2024-05-22</h4>



<div id="vignette-info" class="section level2">
<h2>Vignette Info</h2>
<p>This vignette demonstrates how to use ASCAT to analyse multiple
phylogenetically related samples. For the general usage of ASCAT
including parameters that are not specific to multi-sample analysis
please refer to the <a href="https://www.crick.ac.uk/peter-van-loo/software/ASCAT">ASCAT
webpage</a> and the <a href="https://github.com/Crick-CancerGenomics/ascat/blob/master/ExampleData/ASCAT_examplePipeline.R">example
pipeline</a>.</p>
</div>
<div id="using-ascat-for-multi-sample-analyses" class="section level2">
<h2>Using ASCAT for multi-sample analyses</h2>
<p>We start by loading the ASCAT package.</p>
<div class="sourceCode" id="cb1"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(ASCAT)</span></code></pre></div>
<p>Next we load the data.</p>
<div class="sourceCode" id="cb2"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a>ascat.bcMulti <span class="ot">&lt;-</span> <span class="fu">ascat.loadData</span>(</span>
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a>  <span class="at">Tumor_LogR_file =</span> <span class="fu">system.file</span>(<span class="st">&quot;extdata&quot;</span>, <span class="st">&quot;tumour.logR.txt&quot;</span>, <span class="at">package=</span><span class="st">&quot;ASCAT&quot;</span>),</span>
<span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a>  <span class="at">Tumor_BAF_file =</span> <span class="fu">system.file</span>(<span class="st">&quot;extdata&quot;</span>, <span class="st">&quot;tumour.BAF.txt&quot;</span>, <span class="at">package=</span><span class="st">&quot;ASCAT&quot;</span>),</span>
<span id="cb2-4"><a href="#cb2-4" aria-hidden="true" tabindex="-1"></a>  <span class="at">Germline_LogR_file =</span> <span class="fu">system.file</span>(<span class="st">&quot;extdata&quot;</span>, <span class="st">&quot;singlenormal.logR.txt&quot;</span>, <span class="at">package=</span><span class="st">&quot;ASCAT&quot;</span>),</span>
<span id="cb2-5"><a href="#cb2-5" aria-hidden="true" tabindex="-1"></a>  <span class="at">Germline_BAF_file =</span> <span class="fu">system.file</span>(<span class="st">&quot;extdata&quot;</span>, <span class="st">&quot;singlenormal.BAF.txt&quot;</span>, <span class="at">package=</span><span class="st">&quot;ASCAT&quot;</span>))</span></code></pre></div>
<pre><code>## [1] Reading Tumor LogR data...
## [1] Reading Tumor BAF data...
## [1] Reading Germline LogR data...
## [1] Reading Germline BAF data...
## [1] Registering SNP locations...
## [1] Splitting genome in distinct chunks...</code></pre>
<p>Both <tt>Tumor_LogR_file</tt> and <tt>Tumor_BAF_file</tt> are
expected to contain a column for each of the samples to analyse.</p>
<div class="sourceCode" id="cb4"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a><span class="fu">head</span>(ascat.bcMulti<span class="sc">$</span>Tumor_LogR)                          </span></code></pre></div>
<pre><code>##            S1       S2
## SNP1  0.03615 -1.03950
## SNP2  0.14998 -0.79433
## SNP3 -0.00891 -0.76137
## SNP4  0.40188 -0.67521
## SNP5  0.14902 -0.72980
## SNP6  0.24118 -1.11302</code></pre>
<div class="sourceCode" id="cb6"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a><span class="fu">head</span>(ascat.bcMulti<span class="sc">$</span>Tumor_BAF)       </span></code></pre></div>
<pre><code>##           S1      S2
## SNP1 0.51596 0.99262
## SNP2 0.67903 0.00255
## SNP3 1.00000 1.00000
## SNP4 0.00000 0.00000
## SNP5 1.00000 1.00000
## SNP6 0.45572 0.04925</code></pre>
<p>The next step is to run the segmentation. When analysing
phylogenetically related samples, it is expected that some of the copy
number segment boundaries are shared between samples. In this case a
joint segmentation of all samples is recommended. The synthetic data set
used in this example was also simulated with partly shared segment
boundaries. The ground truth copy number plots of the two samples we are
going to analyse are shown in the following plots.</p>
<p><img src="" style="display: block; margin: auto;" /><img src="" style="display: block; margin: auto;" /></p>
<p>The multi-sample segmentation algorithm can be run using the function
<tt>ascat.asmultipcf</tt>.</p>
<div class="sourceCode" id="cb8"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a>ascat.bcMulti <span class="ot">&lt;-</span> <span class="fu">ascat.asmultipcf</span>(ascat.bcMulti,<span class="at">penalty =</span> <span class="dv">5</span>,<span class="at">out.dir=</span><span class="cn">NA</span>)</span></code></pre></div>
<pre><code>## [1] &quot;Segmentlength 5&quot;</code></pre>
<p>Finally ASCAT can be run on the segmented data set.</p>
<div class="sourceCode" id="cb10"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a>ascat.outputMulti <span class="ot">=</span> <span class="fu">ascat.runAscat</span>(ascat.bcMulti)</span></code></pre></div>
</div>
<div id="comparison-with-single-sample-segmentation" class="section level2">
<h2>Comparison with single sample segmentation</h2>
<p>Finally, we compare our result to that of standard single sample
segmentation using <tt>ascat.aspcf</tt>.</p>
<div class="sourceCode" id="cb11"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a>ascat.bc <span class="ot">=</span> <span class="fu">ascat.loadData</span>(<span class="fu">system.file</span>(<span class="st">&quot;extdata&quot;</span>, <span class="st">&quot;tumour.logR.txt&quot;</span>, <span class="at">package=</span><span class="st">&quot;ASCAT&quot;</span>),</span>
<span id="cb11-2"><a href="#cb11-2" aria-hidden="true" tabindex="-1"></a>                          <span class="fu">system.file</span>(<span class="st">&quot;extdata&quot;</span>, <span class="st">&quot;tumour.BAF.txt&quot;</span>, <span class="at">package=</span><span class="st">&quot;ASCAT&quot;</span>),</span>
<span id="cb11-3"><a href="#cb11-3" aria-hidden="true" tabindex="-1"></a>                          <span class="fu">system.file</span>(<span class="st">&quot;extdata&quot;</span>, <span class="st">&quot;normal.logR.txt&quot;</span>, <span class="at">package=</span><span class="st">&quot;ASCAT&quot;</span>),</span>
<span id="cb11-4"><a href="#cb11-4" aria-hidden="true" tabindex="-1"></a>                          <span class="fu">system.file</span>(<span class="st">&quot;extdata&quot;</span>, <span class="st">&quot;normal.BAF.txt&quot;</span>, <span class="at">package=</span><span class="st">&quot;ASCAT&quot;</span>))</span></code></pre></div>
<pre><code>## [1] Reading Tumor LogR data...
## [1] Reading Tumor BAF data...
## [1] Reading Germline LogR data...
## [1] Reading Germline BAF data...
## [1] Registering SNP locations...
## [1] Splitting genome in distinct chunks...</code></pre>
<div class="sourceCode" id="cb13"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true" tabindex="-1"></a>ascat.bc <span class="ot">=</span> <span class="fu">ascat.aspcf</span>(ascat.bc,<span class="at">penalty =</span> <span class="dv">25</span>,<span class="at">out.dir=</span><span class="cn">NA</span>)</span></code></pre></div>
<pre><code>## [1] Sample S1 (1/2)
## [1] Sample S2 (2/2)</code></pre>
<p>Note that in the single-sample case the same segmentation sensitivity
is achieved with a higher penalty parameter compared to the multi-sample
case. This means, when switching from single- to multi-sample
segmentation, the penalty parameter needs to be lowered to maintain a
similar sensitivity.</p>
<p>We plot the segment boundaries inferred for each of the two samples
by multi- and single-sample segmentation.</p>
<div class="sourceCode" id="cb15"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb15-1"><a href="#cb15-1" aria-hidden="true" tabindex="-1"></a><span class="fu">plot.segments</span>(<span class="at">v1=</span><span class="fu">cumsum</span>(<span class="fu">rle</span>(ascat.bc<span class="sc">$</span>Tumor_LogR_segmented[,<span class="dv">1</span>])<span class="sc">$</span>lengths),</span>
<span id="cb15-2"><a href="#cb15-2" aria-hidden="true" tabindex="-1"></a>              <span class="at">v2=</span><span class="fu">cumsum</span>(<span class="fu">rle</span>(ascat.bc<span class="sc">$</span>Tumor_LogR_segmented[,<span class="dv">2</span>])<span class="sc">$</span>lengths),</span>
<span id="cb15-3"><a href="#cb15-3" aria-hidden="true" tabindex="-1"></a>              <span class="at">main=</span><span class="st">&quot;Single-sample segmentation&quot;</span>)</span>
<span id="cb15-4"><a href="#cb15-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb15-5"><a href="#cb15-5" aria-hidden="true" tabindex="-1"></a><span class="fu">plot.segments</span>(<span class="at">v1=</span><span class="fu">cumsum</span>(<span class="fu">rle</span>(ascat.bcMulti<span class="sc">$</span>Tumor_LogR_segmented[,<span class="dv">1</span>])<span class="sc">$</span>lengths),</span>
<span id="cb15-6"><a href="#cb15-6" aria-hidden="true" tabindex="-1"></a>              <span class="at">v2=</span><span class="fu">cumsum</span>(<span class="fu">rle</span>(ascat.bcMulti<span class="sc">$</span>Tumor_LogR_segmented[,<span class="dv">2</span>])<span class="sc">$</span>lengths),</span>
<span id="cb15-7"><a href="#cb15-7" aria-hidden="true" tabindex="-1"></a>              <span class="at">main=</span><span class="st">&quot;Multi-sample segmentation&quot;</span>)</span></code></pre></div>
<p><img src="" style="display: block; margin: auto;" /><img src="" style="display: block; margin: auto;" />
In case of single-sample segmentation the inferred positions of most of
the shared segment boundaries vary slightly between the two samples,
whereas the multi-sample segmentation infers a common breakpoint when
there is no significant evidence that the boundaries differ between
samples.</p>
<p>##Comparison with another multi-sample copy number method</p>
<p>In order to compare asmultipcf segmentation to other copy number
inference methods, we ran ASCAT on two samples from two patients from a
metastatic prostate cancer study (<a href="https://www.ncbi.nlm.nih.gov/pubmed/25830880">Gundem et al</a>).
For the same study, copy number profiles are available from HATCHet (<a href="https://github.com/raphael-group/hatchet">github repository</a>;
<a href="https://www.biorxiv.org/content/10.1101/496174v1">publication</a>).</p>
<p>Loading all neccessary packages.</p>
<div class="sourceCode" id="cb16"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb16-1"><a href="#cb16-1" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(ggplot2)</span>
<span id="cb16-2"><a href="#cb16-2" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(plyr)</span></code></pre></div>
<p>Because HATCHet can model a mixture of copy number states but ASCAT
only detects the major clone, we need to define the major clone in the
HATCHet data.</p>
<div class="sourceCode" id="cb17"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb17-1"><a href="#cb17-1" aria-hidden="true" tabindex="-1"></a>getMajorClone<span class="ot">&lt;-</span><span class="cf">function</span>(row){</span>
<span id="cb17-2"><a href="#cb17-2" aria-hidden="true" tabindex="-1"></a>  maj<span class="ot">&lt;-</span><span class="fu">names</span>(<span class="fu">which.max</span>(row[<span class="fu">c</span>(<span class="dv">8</span>,<span class="dv">10</span>,<span class="dv">12</span>)]))</span>
<span id="cb17-3"><a href="#cb17-3" aria-hidden="true" tabindex="-1"></a>  maj.cn<span class="ot">&lt;-</span>row[(<span class="fu">match</span>(maj,<span class="fu">names</span>(row))<span class="sc">-</span><span class="dv">1</span>)]</span>
<span id="cb17-4"><a href="#cb17-4" aria-hidden="true" tabindex="-1"></a>  <span class="fu">return</span>(maj.cn)</span>
<span id="cb17-5"><a href="#cb17-5" aria-hidden="true" tabindex="-1"></a>}</span></code></pre></div>
<p>Next we define a function to load HATCHet data, define the major
clone for each segment, i.e. row, and split copy number annotation from
“a|b” format into two columns.</p>
<div class="sourceCode" id="cb18"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb18-1"><a href="#cb18-1" aria-hidden="true" tabindex="-1"></a>readHatchetFile<span class="ot">&lt;-</span><span class="cf">function</span>(path){</span>
<span id="cb18-2"><a href="#cb18-2" aria-hidden="true" tabindex="-1"></a>  hatchet.raw<span class="ot">&lt;-</span><span class="fu">read.table</span>(path, <span class="at">header=</span>F, <span class="at">sep=</span><span class="st">&quot;</span><span class="sc">\t</span><span class="st">&quot;</span>, <span class="at">stringsAsFactors =</span> F)</span>
<span id="cb18-3"><a href="#cb18-3" aria-hidden="true" tabindex="-1"></a>  </span>
<span id="cb18-4"><a href="#cb18-4" aria-hidden="true" tabindex="-1"></a>  <span class="do">##find major clone</span></span>
<span id="cb18-5"><a href="#cb18-5" aria-hidden="true" tabindex="-1"></a>  major.cn<span class="ot">&lt;-</span><span class="fu">apply</span>(hatchet.raw, <span class="dv">1</span>, <span class="cf">function</span>(z) <span class="fu">getMajorClone</span>(z))</span>
<span id="cb18-6"><a href="#cb18-6" aria-hidden="true" tabindex="-1"></a>  hatchet.raw<span class="sc">$</span>major.cn<span class="ot">&lt;-</span>major.cn</span>
<span id="cb18-7"><a href="#cb18-7" aria-hidden="true" tabindex="-1"></a>  </span>
<span id="cb18-8"><a href="#cb18-8" aria-hidden="true" tabindex="-1"></a>  hatchet.short<span class="ot">&lt;-</span>hatchet.raw[<span class="fu">c</span>(<span class="dv">1</span><span class="sc">:</span><span class="dv">4</span>,<span class="dv">13</span>)]</span>
<span id="cb18-9"><a href="#cb18-9" aria-hidden="true" tabindex="-1"></a>  <span class="fu">names</span>(hatchet.short)<span class="ot">&lt;-</span><span class="fu">c</span>(<span class="st">&quot;chr&quot;</span>,<span class="st">&quot;start&quot;</span>,<span class="st">&quot;end&quot;</span>,<span class="st">&quot;sample&quot;</span>,<span class="st">&quot;hatchet.cn&quot;</span>)</span>
<span id="cb18-10"><a href="#cb18-10" aria-hidden="true" tabindex="-1"></a>  </span>
<span id="cb18-11"><a href="#cb18-11" aria-hidden="true" tabindex="-1"></a>  major.cn<span class="ot">&lt;-</span><span class="fu">unlist</span>(<span class="fu">lapply</span>(<span class="fu">strsplit</span>(hatchet.short<span class="sc">$</span>hatchet.cn, <span class="st">&quot;</span><span class="sc">\\</span><span class="st">|&quot;</span>), <span class="cf">function</span>(z) z[<span class="dv">1</span>]))</span>
<span id="cb18-12"><a href="#cb18-12" aria-hidden="true" tabindex="-1"></a>  minor.cn<span class="ot">&lt;-</span><span class="fu">unlist</span>(<span class="fu">lapply</span>(<span class="fu">strsplit</span>(hatchet.short<span class="sc">$</span>hatchet.cn, <span class="st">&quot;</span><span class="sc">\\</span><span class="st">|&quot;</span>), <span class="cf">function</span>(z) z[<span class="dv">2</span>]))</span>
<span id="cb18-13"><a href="#cb18-13" aria-hidden="true" tabindex="-1"></a>  </span>
<span id="cb18-14"><a href="#cb18-14" aria-hidden="true" tabindex="-1"></a>  hatchet.short<span class="sc">$</span>major.cn<span class="ot">&lt;-</span>major.cn</span>
<span id="cb18-15"><a href="#cb18-15" aria-hidden="true" tabindex="-1"></a>  hatchet.short<span class="sc">$</span>minor.cn<span class="ot">&lt;-</span>minor.cn</span>
<span id="cb18-16"><a href="#cb18-16" aria-hidden="true" tabindex="-1"></a>  </span>
<span id="cb18-17"><a href="#cb18-17" aria-hidden="true" tabindex="-1"></a>  <span class="fu">return</span>(hatchet.short[<span class="sc">-</span><span class="dv">5</span>])</span>
<span id="cb18-18"><a href="#cb18-18" aria-hidden="true" tabindex="-1"></a>}</span></code></pre></div>
<p>In order to provide a quantitative measure of how much ASCAT using
asmultipcf and HATCHet agree with regard to the sample segmentation, we
analysed what fraction of asmultipcf breakpoints has a corresponding
HATCHet breakpoint. First, we centred the ASCAT breakpoints in the
middle of two segments.</p>
<div class="sourceCode" id="cb19"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb19-1"><a href="#cb19-1" aria-hidden="true" tabindex="-1"></a>returnBreakpoints<span class="ot">&lt;-</span><span class="cf">function</span>(df.chr){</span>
<span id="cb19-2"><a href="#cb19-2" aria-hidden="true" tabindex="-1"></a>  bp.df<span class="ot">&lt;-</span><span class="cn">NULL</span></span>
<span id="cb19-3"><a href="#cb19-3" aria-hidden="true" tabindex="-1"></a>  df.sorted<span class="ot">&lt;-</span>df.chr[<span class="fu">order</span>(df.chr<span class="sc">$</span>start),]</span>
<span id="cb19-4"><a href="#cb19-4" aria-hidden="true" tabindex="-1"></a>  <span class="cf">for</span>(i <span class="cf">in</span> <span class="dv">1</span><span class="sc">:</span>(<span class="fu">nrow</span>(df.sorted)<span class="sc">-</span><span class="dv">1</span>)){</span>
<span id="cb19-5"><a href="#cb19-5" aria-hidden="true" tabindex="-1"></a>    first<span class="ot">&lt;-</span>df.sorted[i,]</span>
<span id="cb19-6"><a href="#cb19-6" aria-hidden="true" tabindex="-1"></a>    second<span class="ot">&lt;-</span>df.sorted[(i<span class="sc">+</span><span class="dv">1</span>),]</span>
<span id="cb19-7"><a href="#cb19-7" aria-hidden="true" tabindex="-1"></a>    <span class="do">##verify real cn bp</span></span>
<span id="cb19-8"><a href="#cb19-8" aria-hidden="true" tabindex="-1"></a>    <span class="cf">if</span>(first<span class="sc">$</span>major.cn<span class="sc">==</span>second<span class="sc">$</span>major.cn <span class="sc">&amp;</span> first<span class="sc">$</span>minor.cn<span class="sc">==</span>second<span class="sc">$</span>minor.cn){</span>
<span id="cb19-9"><a href="#cb19-9" aria-hidden="true" tabindex="-1"></a>      <span class="fu">print</span>(<span class="st">&quot;Consecutive rows have identical CN!&quot;</span>)</span>
<span id="cb19-10"><a href="#cb19-10" aria-hidden="true" tabindex="-1"></a>    }</span>
<span id="cb19-11"><a href="#cb19-11" aria-hidden="true" tabindex="-1"></a>    <span class="cf">else</span>{</span>
<span id="cb19-12"><a href="#cb19-12" aria-hidden="true" tabindex="-1"></a>      bp.df<span class="ot">&lt;-</span><span class="fu">rbind</span>(bp.df, <span class="fu">data.frame</span>(<span class="at">bp.location=</span>(first<span class="sc">$</span>end<span class="sc">+</span>((second<span class="sc">$</span>start<span class="sc">-</span>first<span class="sc">$</span>end)<span class="sc">/</span><span class="dv">2</span>))))</span>
<span id="cb19-13"><a href="#cb19-13" aria-hidden="true" tabindex="-1"></a>    }</span>
<span id="cb19-14"><a href="#cb19-14" aria-hidden="true" tabindex="-1"></a>  }</span>
<span id="cb19-15"><a href="#cb19-15" aria-hidden="true" tabindex="-1"></a>  <span class="fu">return</span>(bp.df)</span>
<span id="cb19-16"><a href="#cb19-16" aria-hidden="true" tabindex="-1"></a>}</span></code></pre></div>
<p>HATCHet output is provided for 50kb bins and not specifically
segmented. Hence, in order to compare consecutive segments with the same
major clonal copy number, we are merging neighbouring segments with
matching allele specific copy number values. Then we calculate the
distance of the closest HATCHet breakpoint for every asmultipcf
breakpoint.</p>
<div class="sourceCode" id="cb20"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb20-1"><a href="#cb20-1" aria-hidden="true" tabindex="-1"></a>findMatchingBPs<span class="ot">&lt;-</span><span class="cf">function</span>(ascat.bps, hatchet.segs){</span>
<span id="cb20-2"><a href="#cb20-2" aria-hidden="true" tabindex="-1"></a>  <span class="do">##limit hatchet df to true CN segs</span></span>
<span id="cb20-3"><a href="#cb20-3" aria-hidden="true" tabindex="-1"></a>  hatchet.true<span class="ot">&lt;-</span><span class="cn">NULL</span></span>
<span id="cb20-4"><a href="#cb20-4" aria-hidden="true" tabindex="-1"></a>  hatchet.sorted<span class="ot">&lt;-</span>hatchet.segs[<span class="fu">order</span>(hatchet.segs<span class="sc">$</span>start),]</span>
<span id="cb20-5"><a href="#cb20-5" aria-hidden="true" tabindex="-1"></a>  </span>
<span id="cb20-6"><a href="#cb20-6" aria-hidden="true" tabindex="-1"></a>  rles<span class="ot">&lt;-</span><span class="fu">rle</span>(<span class="fu">paste0</span>(hatchet.sorted<span class="sc">$</span>major.cn,<span class="st">&quot;_&quot;</span>,hatchet.sorted<span class="sc">$</span>minor.cn))<span class="sc">$</span>lengths</span>
<span id="cb20-7"><a href="#cb20-7" aria-hidden="true" tabindex="-1"></a>  idx<span class="ot">&lt;-</span><span class="dv">1</span></span>
<span id="cb20-8"><a href="#cb20-8" aria-hidden="true" tabindex="-1"></a>  <span class="cf">for</span>(k <span class="cf">in</span> rles){</span>
<span id="cb20-9"><a href="#cb20-9" aria-hidden="true" tabindex="-1"></a>    hatchet.true<span class="ot">&lt;-</span><span class="fu">rbind</span>(hatchet.true, <span class="fu">data.frame</span>(<span class="at">start=</span>hatchet.sorted[idx, <span class="st">&quot;start&quot;</span>], <span class="at">end=</span>hatchet.sorted[(idx<span class="sc">+</span>k<span class="dv">-1</span>), <span class="st">&quot;end&quot;</span>]))</span>
<span id="cb20-10"><a href="#cb20-10" aria-hidden="true" tabindex="-1"></a>    idx<span class="ot">&lt;-</span>(idx<span class="sc">+</span>k)</span>
<span id="cb20-11"><a href="#cb20-11" aria-hidden="true" tabindex="-1"></a>  }</span>
<span id="cb20-12"><a href="#cb20-12" aria-hidden="true" tabindex="-1"></a>  </span>
<span id="cb20-13"><a href="#cb20-13" aria-hidden="true" tabindex="-1"></a>  ascat.flag<span class="ot">&lt;-</span><span class="cn">NULL</span></span>
<span id="cb20-14"><a href="#cb20-14" aria-hidden="true" tabindex="-1"></a>  <span class="cf">for</span>(i <span class="cf">in</span> <span class="dv">1</span><span class="sc">:</span><span class="fu">nrow</span>(ascat.bps)){</span>
<span id="cb20-15"><a href="#cb20-15" aria-hidden="true" tabindex="-1"></a>    ascat.bp<span class="ot">&lt;-</span>ascat.bps[i,<span class="st">&quot;bp.location&quot;</span>]</span>
<span id="cb20-16"><a href="#cb20-16" aria-hidden="true" tabindex="-1"></a>    min.dist<span class="ot">&lt;-</span><span class="fu">min</span>(<span class="fu">c</span>(<span class="fu">abs</span>(ascat.bp<span class="sc">-</span>hatchet.true<span class="sc">$</span>end),<span class="fu">abs</span>(ascat.bp<span class="sc">-</span>hatchet.true<span class="sc">$</span>start)))</span>
<span id="cb20-17"><a href="#cb20-17" aria-hidden="true" tabindex="-1"></a>    </span>
<span id="cb20-18"><a href="#cb20-18" aria-hidden="true" tabindex="-1"></a>    ascat.flag<span class="ot">&lt;-</span><span class="fu">rbind</span>(ascat.flag, <span class="fu">data.frame</span>(<span class="at">bkp=</span>ascat.bp, <span class="at">min.dist=</span>min.dist))</span>
<span id="cb20-19"><a href="#cb20-19" aria-hidden="true" tabindex="-1"></a>  }</span>
<span id="cb20-20"><a href="#cb20-20" aria-hidden="true" tabindex="-1"></a>  <span class="fu">return</span>(ascat.flag)</span>
<span id="cb20-21"><a href="#cb20-21" aria-hidden="true" tabindex="-1"></a>}</span></code></pre></div>
<p>This is the main function visualising the copy number of asmultipcf
and HATCHet for all four analysed samples and calculates the fraction of
ASCAT breakpoints with a HATCHet breakpoint fewer than 50kb bases away
(size of HATCHet bins).</p>
<div class="sourceCode" id="cb21"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb21-1"><a href="#cb21-1" aria-hidden="true" tabindex="-1"></a>compareCN<span class="ot">&lt;-</span><span class="cf">function</span>(cn.ascat, cn.hatchet){</span>
<span id="cb21-2"><a href="#cb21-2" aria-hidden="true" tabindex="-1"></a>  <span class="do">##split into samples</span></span>
<span id="cb21-3"><a href="#cb21-3" aria-hidden="true" tabindex="-1"></a>  shared.samples<span class="ot">&lt;-</span><span class="fu">intersect</span>(cn.ascat<span class="sc">$</span>sample, cn.hatchet<span class="sc">$</span>sample)</span>
<span id="cb21-4"><a href="#cb21-4" aria-hidden="true" tabindex="-1"></a>  </span>
<span id="cb21-5"><a href="#cb21-5" aria-hidden="true" tabindex="-1"></a>  <span class="cf">for</span>(s <span class="cf">in</span> shared.samples){</span>
<span id="cb21-6"><a href="#cb21-6" aria-hidden="true" tabindex="-1"></a>    ascat.sub<span class="ot">&lt;-</span>cn.ascat[cn.ascat<span class="sc">$</span>sample<span class="sc">==</span>s,]</span>
<span id="cb21-7"><a href="#cb21-7" aria-hidden="true" tabindex="-1"></a>    hatchet.sub<span class="ot">&lt;-</span>cn.hatchet[cn.hatchet<span class="sc">$</span>sample<span class="sc">==</span>s,]</span>
<span id="cb21-8"><a href="#cb21-8" aria-hidden="true" tabindex="-1"></a>    <span class="do">##move values slightly for plotting</span></span>
<span id="cb21-9"><a href="#cb21-9" aria-hidden="true" tabindex="-1"></a>    ascat.plot<span class="ot">&lt;-</span> ascat.sub</span>
<span id="cb21-10"><a href="#cb21-10" aria-hidden="true" tabindex="-1"></a>    hatchet.plot<span class="ot">&lt;-</span> hatchet.sub</span>
<span id="cb21-11"><a href="#cb21-11" aria-hidden="true" tabindex="-1"></a>    ascat.plot<span class="sc">$</span>major.cn<span class="ot">&lt;-</span>(<span class="fu">as.numeric</span>(ascat.plot<span class="sc">$</span>major.cn)<span class="sc">+</span><span class="fl">0.1</span>)</span>
<span id="cb21-12"><a href="#cb21-12" aria-hidden="true" tabindex="-1"></a>    hatchet.plot<span class="sc">$</span>major.cn<span class="ot">&lt;-</span>(<span class="fu">as.numeric</span>(hatchet.plot<span class="sc">$</span>major.cn)<span class="sc">-</span><span class="fl">0.1</span>)</span>
<span id="cb21-13"><a href="#cb21-13" aria-hidden="true" tabindex="-1"></a>    </span>
<span id="cb21-14"><a href="#cb21-14" aria-hidden="true" tabindex="-1"></a>    <span class="do">##visualise</span></span>
<span id="cb21-15"><a href="#cb21-15" aria-hidden="true" tabindex="-1"></a>    joint.df<span class="ot">&lt;-</span><span class="fu">rbind</span>(ascat.plot,hatchet.plot)</span>
<span id="cb21-16"><a href="#cb21-16" aria-hidden="true" tabindex="-1"></a>    joint.df<span class="sc">$</span>chr<span class="ot">&lt;-</span><span class="fu">factor</span>(joint.df<span class="sc">$</span>chr, <span class="at">levels=</span><span class="fu">c</span>(<span class="dv">1</span><span class="sc">:</span><span class="dv">22</span>,<span class="st">&quot;X&quot;</span>,<span class="st">&quot;Y&quot;</span>))</span>
<span id="cb21-17"><a href="#cb21-17" aria-hidden="true" tabindex="-1"></a>    p1<span class="ot">&lt;-</span><span class="fu">ggplot</span>(joint.df, <span class="fu">aes</span>(<span class="at">x=</span>start, <span class="at">y=</span>(<span class="fu">as.numeric</span>(major.cn)<span class="sc">+</span><span class="fu">as.numeric</span>(minor.cn)), <span class="at">xend=</span>end, <span class="at">yend=</span>(<span class="fu">as.numeric</span>(major.cn)<span class="sc">+</span><span class="fu">as.numeric</span>(minor.cn)), <span class="at">col=</span><span class="fu">as.factor</span>(method)))<span class="sc">+</span></span>
<span id="cb21-18"><a href="#cb21-18" aria-hidden="true" tabindex="-1"></a>      <span class="fu">geom_segment</span>()<span class="sc">+</span></span>
<span id="cb21-19"><a href="#cb21-19" aria-hidden="true" tabindex="-1"></a>      <span class="fu">theme</span>(<span class="at">axis.text.x=</span><span class="fu">element_text</span>(<span class="at">angle=</span><span class="dv">45</span>,<span class="at">hjust=</span><span class="dv">1</span>), <span class="at">panel.background =</span> <span class="fu">element_blank</span>(), <span class="at">panel.grid.major =</span> <span class="fu">element_line</span>(<span class="at">color=</span><span class="st">&quot;grey80&quot;</span>))<span class="sc">+</span></span>
<span id="cb21-20"><a href="#cb21-20" aria-hidden="true" tabindex="-1"></a>      <span class="fu">ggtitle</span>(<span class="fu">paste0</span>(<span class="st">&quot;Sample &quot;</span>,s))<span class="sc">+</span></span>
<span id="cb21-21"><a href="#cb21-21" aria-hidden="true" tabindex="-1"></a>      <span class="fu">scale_color_manual</span>(<span class="at">values=</span><span class="fu">c</span>(<span class="st">&quot;cyan4&quot;</span>,<span class="st">&quot;coral3&quot;</span>), <span class="at">name=</span><span class="st">&quot;&quot;</span>)<span class="sc">+</span></span>
<span id="cb21-22"><a href="#cb21-22" aria-hidden="true" tabindex="-1"></a>      <span class="fu">scale_x_continuous</span>(<span class="at">name=</span><span class="st">&quot;&quot;</span>)<span class="sc">+</span></span>
<span id="cb21-23"><a href="#cb21-23" aria-hidden="true" tabindex="-1"></a>      <span class="fu">scale_y_continuous</span>(<span class="at">name=</span><span class="st">&quot;Copy number&quot;</span>, <span class="at">limits=</span>(<span class="fu">c</span>(<span class="dv">0</span>,<span class="dv">15</span>)))<span class="sc">+</span></span>
<span id="cb21-24"><a href="#cb21-24" aria-hidden="true" tabindex="-1"></a>      <span class="fu">facet_wrap</span>(.<span class="sc">~</span>chr, <span class="at">scales =</span> <span class="st">&quot;free_x&quot;</span>, <span class="at">nrow =</span> <span class="dv">3</span>)</span>
<span id="cb21-25"><a href="#cb21-25" aria-hidden="true" tabindex="-1"></a>    <span class="fu">print</span>(p1)</span>
<span id="cb21-26"><a href="#cb21-26" aria-hidden="true" tabindex="-1"></a>    </span>
<span id="cb21-27"><a href="#cb21-27" aria-hidden="true" tabindex="-1"></a>    </span>
<span id="cb21-28"><a href="#cb21-28" aria-hidden="true" tabindex="-1"></a>    <span class="do">##give quality in measure: what fraction of ASCAT bp has hatchet bp in &lt; threshold vincinity?</span></span>
<span id="cb21-29"><a href="#cb21-29" aria-hidden="true" tabindex="-1"></a>    bps<span class="ot">&lt;-</span><span class="fu">ddply</span>(ascat.sub, .(chr), <span class="cf">function</span>(z) <span class="fu">returnBreakpoints</span>(z))</span>
<span id="cb21-30"><a href="#cb21-30" aria-hidden="true" tabindex="-1"></a>    bp.list<span class="ot">&lt;-</span><span class="fu">split</span>(bps, bps<span class="sc">$</span>chr)</span>
<span id="cb21-31"><a href="#cb21-31" aria-hidden="true" tabindex="-1"></a>    </span>
<span id="cb21-32"><a href="#cb21-32" aria-hidden="true" tabindex="-1"></a>    bkp.list<span class="ot">&lt;-</span><span class="cn">NULL</span></span>
<span id="cb21-33"><a href="#cb21-33" aria-hidden="true" tabindex="-1"></a>    <span class="cf">for</span>(c <span class="cf">in</span> <span class="fu">names</span>(bp.list)){</span>
<span id="cb21-34"><a href="#cb21-34" aria-hidden="true" tabindex="-1"></a>      <span class="cf">if</span>(c<span class="sc">!=</span><span class="st">&quot;X&quot;</span>){</span>
<span id="cb21-35"><a href="#cb21-35" aria-hidden="true" tabindex="-1"></a>        bkp.list<span class="ot">&lt;-</span><span class="fu">rbind</span>(bkp.list,<span class="fu">findMatchingBPs</span>(bp.list[[c]], hatchet.sub[hatchet.sub<span class="sc">$</span>chr<span class="sc">==</span>c,]))</span>
<span id="cb21-36"><a href="#cb21-36" aria-hidden="true" tabindex="-1"></a>      }</span>
<span id="cb21-37"><a href="#cb21-37" aria-hidden="true" tabindex="-1"></a>    }</span>
<span id="cb21-38"><a href="#cb21-38" aria-hidden="true" tabindex="-1"></a>    <span class="do">##use bin size of HATCHet as threshold</span></span>
<span id="cb21-39"><a href="#cb21-39" aria-hidden="true" tabindex="-1"></a>    threshold<span class="ot">=</span><span class="dv">50000</span></span>
<span id="cb21-40"><a href="#cb21-40" aria-hidden="true" tabindex="-1"></a>    bkp.list<span class="sc">$</span>match<span class="ot">&lt;-</span><span class="fu">ifelse</span>(bkp.list<span class="sc">$</span>min.dist<span class="sc">&lt;</span>threshold,T,F)</span>
<span id="cb21-41"><a href="#cb21-41" aria-hidden="true" tabindex="-1"></a>    <span class="fu">print</span>(s)</span>
<span id="cb21-42"><a href="#cb21-42" aria-hidden="true" tabindex="-1"></a>    <span class="fu">print</span>(<span class="fu">prop.table</span>(<span class="fu">table</span>(bkp.list<span class="sc">$</span>match)))</span>
<span id="cb21-43"><a href="#cb21-43" aria-hidden="true" tabindex="-1"></a>  }</span>
<span id="cb21-44"><a href="#cb21-44" aria-hidden="true" tabindex="-1"></a>}</span></code></pre></div>
<p>Now we can carry out the comparison. Load the HATCHet segmentation
for patient A32.</p>
<div class="sourceCode" id="cb22"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb22-1"><a href="#cb22-1" aria-hidden="true" tabindex="-1"></a>path<span class="ot">&lt;-</span><span class="st">&quot;https://raw.githubusercontent.com/raphael-group/hatchet-paper/master/cancer/prostate/A32/best.seg.ucn&quot;</span></span>
<span id="cb22-2"><a href="#cb22-2" aria-hidden="true" tabindex="-1"></a>hatchet.seg<span class="ot">&lt;-</span><span class="fu">readHatchetFile</span>(path)</span>
<span id="cb22-3"><a href="#cb22-3" aria-hidden="true" tabindex="-1"></a>hatchet.seg<span class="sc">$</span>method<span class="ot">&lt;-</span><span class="st">&quot;HATCHet&quot;</span></span>
<span id="cb22-4"><a href="#cb22-4" aria-hidden="true" tabindex="-1"></a>hatchet.seg<span class="sc">$</span>sample<span class="ot">&lt;-</span><span class="fu">gsub</span>(<span class="st">&quot;-&quot;</span>,<span class="st">&quot;&quot;</span>,hatchet.seg<span class="sc">$</span>sample)</span></code></pre></div>
<p>Now we can load the asmultipcf results for patient A32.</p>
<div class="sourceCode" id="cb23"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb23-1"><a href="#cb23-1" aria-hidden="true" tabindex="-1"></a>ascat.seg<span class="ot">&lt;-</span><span class="fu">read.table</span>(<span class="fu">system.file</span>(<span class="st">&quot;extdata&quot;</span>, <span class="st">&quot;A32.fast.segments.txt&quot;</span>, <span class="at">package=</span><span class="st">&quot;ASCAT&quot;</span>), <span class="at">header=</span>T, <span class="at">sep=</span><span class="st">&quot;</span><span class="sc">\t</span><span class="st">&quot;</span>, <span class="at">stringsAsFactors =</span> F)</span>
<span id="cb23-2"><a href="#cb23-2" aria-hidden="true" tabindex="-1"></a>ascat.seg<span class="sc">$</span>tmp<span class="ot">&lt;-</span><span class="fu">unlist</span>(<span class="fu">lapply</span>(<span class="fu">strsplit</span>(ascat.seg<span class="sc">$</span>sample, <span class="st">&quot;-&quot;</span>), <span class="cf">function</span>(z) z[<span class="dv">1</span>]))</span>
<span id="cb23-3"><a href="#cb23-3" aria-hidden="true" tabindex="-1"></a>ascat.seg<span class="ot">&lt;-</span>ascat.seg[<span class="sc">-</span><span class="dv">1</span>]</span>
<span id="cb23-4"><a href="#cb23-4" aria-hidden="true" tabindex="-1"></a><span class="fu">names</span>(ascat.seg)<span class="ot">&lt;-</span><span class="fu">c</span>(<span class="st">&quot;chr&quot;</span>,<span class="st">&quot;start&quot;</span>,<span class="st">&quot;end&quot;</span>,<span class="st">&quot;major.cn&quot;</span>,<span class="st">&quot;minor.cn&quot;</span>,<span class="st">&quot;sample&quot;</span>)</span>
<span id="cb23-5"><a href="#cb23-5" aria-hidden="true" tabindex="-1"></a>ascat.seg<span class="sc">$</span>method<span class="ot">&lt;-</span><span class="st">&quot;ASCAT&quot;</span></span></code></pre></div>
<p>Finally, we can create the visual and segmentation comparison between
the copy number of asmultipcf and HATCHet.</p>
<div class="sourceCode" id="cb24"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb24-1"><a href="#cb24-1" aria-hidden="true" tabindex="-1"></a><span class="fu">compareCN</span>(ascat.seg, hatchet.seg)</span></code></pre></div>
<p><img src="" style="display: block; margin: auto;" /></p>
<pre><code>## [1] &quot;A32C&quot;
## 
##     FALSE      TRUE 
## 0.3591331 0.6408669</code></pre>
<p><img src="" style="display: block; margin: auto;" /></p>
<pre><code>## [1] &quot;A32A&quot;
## 
##     FALSE      TRUE 
## 0.4606061 0.5393939</code></pre>
<p>So for both samples of patient A32, between 54% and 64% of asmultipcf
breakpoints have a corresponding HATCHet breakpoint.</p>
<p>We can now repeat the same analysis for patient A17.</p>
<div class="sourceCode" id="cb27"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb27-1"><a href="#cb27-1" aria-hidden="true" tabindex="-1"></a>path<span class="ot">&lt;-</span><span class="st">&quot;https://raw.githubusercontent.com/raphael-group/hatchet-paper/master/cancer/prostate/A17/best.seg.ucn&quot;</span></span>
<span id="cb27-2"><a href="#cb27-2" aria-hidden="true" tabindex="-1"></a>hatchet.seg<span class="ot">&lt;-</span><span class="fu">readHatchetFile</span>(path)</span>
<span id="cb27-3"><a href="#cb27-3" aria-hidden="true" tabindex="-1"></a>hatchet.seg<span class="sc">$</span>method<span class="ot">&lt;-</span><span class="st">&quot;HATCHet&quot;</span></span>
<span id="cb27-4"><a href="#cb27-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb27-5"><a href="#cb27-5" aria-hidden="true" tabindex="-1"></a>ascat.seg<span class="ot">&lt;-</span><span class="fu">read.table</span>(<span class="fu">system.file</span>(<span class="st">&quot;extdata&quot;</span>, <span class="st">&quot;A17.fast.segments.txt&quot;</span>, <span class="at">package=</span><span class="st">&quot;ASCAT&quot;</span>), <span class="at">header=</span>T, <span class="at">sep=</span><span class="st">&quot;</span><span class="sc">\t</span><span class="st">&quot;</span>, <span class="at">stringsAsFactors =</span> F)</span>
<span id="cb27-6"><a href="#cb27-6" aria-hidden="true" tabindex="-1"></a>ascat.seg<span class="sc">$</span>tmp<span class="ot">&lt;-</span><span class="fu">unlist</span>(<span class="fu">lapply</span>(<span class="fu">strsplit</span>(ascat.seg<span class="sc">$</span>sample, <span class="st">&quot;-&quot;</span>), <span class="cf">function</span>(z) z[<span class="dv">1</span>]))</span>
<span id="cb27-7"><a href="#cb27-7" aria-hidden="true" tabindex="-1"></a>ascat.seg<span class="ot">&lt;-</span>ascat.seg[<span class="sc">-</span><span class="dv">1</span>]</span>
<span id="cb27-8"><a href="#cb27-8" aria-hidden="true" tabindex="-1"></a><span class="fu">names</span>(ascat.seg)<span class="ot">&lt;-</span><span class="fu">c</span>(<span class="st">&quot;chr&quot;</span>,<span class="st">&quot;start&quot;</span>,<span class="st">&quot;end&quot;</span>,<span class="st">&quot;major.cn&quot;</span>,<span class="st">&quot;minor.cn&quot;</span>,<span class="st">&quot;sample&quot;</span>)</span>
<span id="cb27-9"><a href="#cb27-9" aria-hidden="true" tabindex="-1"></a>ascat.seg<span class="sc">$</span>method<span class="ot">&lt;-</span><span class="st">&quot;ASCAT&quot;</span></span></code></pre></div>
<div class="sourceCode" id="cb28"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb28-1"><a href="#cb28-1" aria-hidden="true" tabindex="-1"></a><span class="fu">compareCN</span>(ascat.seg, hatchet.seg)</span></code></pre></div>
<p><img src="" style="display: block; margin: auto;" /></p>
<pre><code>## [1] &quot;A17F&quot;
## 
##     FALSE      TRUE 
## 0.2039801 0.7960199</code></pre>
<p><img src="" style="display: block; margin: auto;" /></p>
<pre><code>## [1] &quot;A17A&quot;
## 
##     FALSE      TRUE 
## 0.1955017 0.8044983</code></pre>
<p>For both samples of patient A17, around 80% of asmultipcf breakpoints
have a corresponding HATCHet breakpoint.</p>
</div>



<!-- code folding -->


<!-- dynamically load mathjax for compatibility with self-contained -->
<script>
  (function () {
    var script = document.createElement("script");
    script.type = "text/javascript";
    script.src  = "https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML";
    document.getElementsByTagName("head")[0].appendChild(script);
  })();
</script>

</body>
</html>
